package com.aaa.javaweb.dao.impl;

import com.aaa.javaweb.dao.TongjiDao;
import com.aaa.javaweb.until.JDBCUntil;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TongjiDaoImpl implements TongjiDao {
    @Override
    public List<Map> settongji() {
        List list = new ArrayList<>();
        String sql1="select * from t_type";
        List<Map> maps = JDBCUntil.selectMap(sql1);
        Map map = new HashMap<>();
        for (int i = 0; i < maps.size(); i++) {

            int id = Integer.parseInt(maps.get(i).get("id")+"");

            if(id==i+1){

                for (int j = 1; j <=12 ; j++) {
                    String tname = maps.get(i).get("tname")+"";
                    map.put("name",tname);
                    String sql="select MONTH(createtime),SUM(price),t_type.tname  from t_order LEFT JOIN t_type on  t_type.id=t_order.roomtype where ";
                    sql+=" t_type.id="+id;
                    sql+=" and MONTH(createtime)="+j;
                    sql+=" GROUP BY  MONTH(createtime)";
                    List<Map> maps1 = JDBCUntil.selectMap(sql);
                    for (Map map1 : maps1) {
                        String o = map1.get("MONTH(createtime)")+"";
                        map.put("month",o);
                    }

                }
            }

        }
        list.add(map);

       // String sql2="select MONTH(createtime),SUM(price),t_type.tname  from t_order LEFT JOIN t_type on  t_type.id=t_order.roomtype where t_type.tname='?' GROUP BY  MONTH(createtime)";
        return list;
    }
}
